package service

import (
	"context"
	pb "shop-demo/api/shop/admin/v1"
	"shop-demo/app/shop/admin/internal/biz"
)

func (s *ShopService) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginReply, error) {
	user, err := s.auc.Login(ctx, &biz.User{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return nil, err
	}
	return &pb.LoginReply{Token: "" + user.Username}, nil
}

func (s *ShopService) Register(ctx context.Context, req *pb.RegisterReq) (*pb.RegisterReply, error) {
	_, err := s.auc.Register(ctx, &biz.User{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return nil, err
	}
	return &pb.RegisterReply{}, nil
}
